﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Twittit.Business
{
    public class SubscriptionService
    {
        private Twittit.DataAccess.DatabaseEntities data;
        private static SubscriptionService instance;

        private SubscriptionService()
        {
            data = new Twittit.DataAccess.DatabaseEntities();
        }

        public static SubscriptionService getInstance()
        {
            if (instance == null)
                instance = new SubscriptionService();
            return instance;
        }

        public Twittit.DataAccess.Subscription getSubscription(int sub, int usr)
        {
            try
            {
                return data.Subscription.Where(s => s.user_id == usr).Where(s => s.subscriber == sub).First();
                 
            }
            catch (Exception e)
            { return null; }
        }

        public Twittit.DataAccess.Subscription confirmSubscription(int s, int u)
        {
            Twittit.DataAccess.Subscription sub = this.getSubscription(s, u);
            sub.confirm = 1;
            data.SaveChanges();
            return sub;
        }
    }
}
